package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.PestBean;
import com.project.dao.PestDao;
import com.project.service.PestService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 虫害
 */

@Service
@Transactional
public class PestServiceImpl extends ServiceImpl<PestDao, PestBean> implements PestService {
    @Override
    public IPage<PestBean> findAllPest(int pageNo, int pageSize) {
        Page<PestBean> page = new Page<>(pageNo,pageSize);
        IPage<PestBean> iPage = this.page(page);
        return iPage;
    }

    @Override
    public void addPest(PestBean pest) {
        this.baseMapper.addPest(pest);
    }

    @Override
    public PestBean findId(Integer pestId) {
        return this.baseMapper.findId(pestId);
    }

    @Override
    public IPage<PestBean> findName(int pageNo, int pageSize,
                                    String pestName, String pestHost) {
        Page<PestBean> page = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (pestName!=null && !pestName.equals("")){
            wrapper.like("f_pestName",pestName);
        }
        if (pestHost!=null && !pestHost.equals("")){
            wrapper.like("f_pestHost",pestHost);
        }
        IPage<PestBean> iPage = this.page(page,wrapper);
        return iPage;
    }
}
